﻿using AuthCenter.Api.Write.Application.Command.Role;
using AuthCenter.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace AuthCenter.Api.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RoleController : ControllerBase
    {
        private readonly IMediator mediator;
        public RoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> AddRole(AddRoleCommand request) 
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<ApiResult<int>> DeleteRole([FromQuery] DeleteRoleCommand request) 
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 编辑角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateRole(UpdateRoleCommand request) 
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 添加用户角色
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> AddUserModel(AddUserModelCommand request) 
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 删除员工与角色的关系
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="roleid"></param>
        /// <returns></returns>
        [HttpDelete]
        public Task<ApiResult<int>> DeleteUserRole([FromQuery] DeleteUserRoleCommand request) 
        {
            return mediator.Send(request);
        }
    }
}
